<template lang="html">
  <div class="home">

    <!-- <div class='clearfix'>
      <el-button type="danger" class='pull-right mb10' icon="el-icon-delete" style='margin-right:10px;' @click="tourl('/content/trash')">回收箱</el-button>
    </div> -->

    <div class='searchView'>
      <el-form :inline="true" class="demo-form-inline">
        
        <el-form-item label="">
          <el-select placeholder="请选择类型" v-model='status'>
            <el-option :label="i.label" :value="i.value" v-for='(i,index) in options' :key='index'></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" >查询</el-button>
        </el-form-item>

      </el-form>
    </div>

    <div class='tableView'>
      <el-tag type="info" class='mb10'>共{{totalData}}条记录</el-tag>
      <el-table
        ref="multipleTable"
        :data="tableData"
        v-loading='loading'
        align='center'
        border
        height='500'
        tooltip-effect="dark">

<!--         <el-table-column
        align='center'
        label="用户头像">
          <template slot-scope="scope">
            <img :src="scope.row.avatar" class='cover'>
          </template>
        </el-table-column> -->

        <el-table-column
        align='center'
        prop='penName'
        label="笔名">
        </el-table-column>

        <el-table-column
        align='center'
        prop='comment'
        label="评论内容">
        </el-table-column>

        <el-table-column
        align='center'
        prop='createTime'
        label="评论时间">
        </el-table-column>

        <el-table-column
        label=""
        width='220'
        align='center'>
          <template slot-scope="scope">
            <el-button size='mini' type="danger" @click='delIt(scope.row.id)'>删除</el-button>
          </template>
        </el-table-column>

      </el-table>

      <div class="pageBlock">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-size="pageSize"
          layout="prev, pager, next, jumper, sizes"
          :total="totalData">
        </el-pagination>
      </div>
    </div>

    <el-dialog
      title="回复内容"
      :visible.sync="dialogVisible"
      width="500px">

      <el-form ref="form" label-width="100px">
        <el-form-item label="回复内容">
          <el-input type='textarea' rows='4' placeholder='请输入回复内容'></el-input>
        </el-form-item>
      </el-form>
      
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitAdd">回 复</el-button>
      </span>
    </el-dialog>

  </div>
</template>
<script>
export default {

  data () {
    return {
      tableData:[],
      loading:false,
      status:0,
      date:'',
      options: [
        {
          value: 0,
          label: '文章'
        },
        {
          value: 1,
          label:'书籍'
        }
      ],
      totalData:0,
      pageSize:10,
      searchUserId:null,
      currentPage:1,
      dialogVisible:false
    }
  },
  watch:{
    status(val){
      this.getList(1);
    }
  },
  methods:{
    submitAdd(){
      this.dialogVisible = false;
      tools.toastOk('回复成功');
    },
    delIt(id){
      this.$confirm('是否确认删除？',{center:true})
      .then(res =>{

        this.loading = true;
        tools.ajax({
          url: this.status == 0 ? '/v1/article/comment/delete' : '/v1/book/comment/delete',
          type:'DELETE',
          data:{
            commentId:id
          }
        })
        .then(res => {
          this.loading = false;
          if(res.code == 200){
            tools.toastOk('删除成功');
            this.getList(1);
          }
        })
        .catch(e => {
          this.loading = false;
        })

      }).catch( e=> {})
    },
    create(){
      if(!this.searchUserId){
        tools.toastWarn('请选择用户');
        return
      };

      this.tourl('/content/user/create',{userId:this.searchUserId});
    },
    tourl(url,query){
      tools.router.push({path:url,query:query || {}})
    },
    getList(page){
      if(page){
        this.currentPage = page;
      }

      let url = '';
      if(this.status == 0){
        url = '/v1/article/comment/getCommentList';
      }else{
        url = '/v1/book/comment/getCommentList';
      };

      this.loading = true;
      tools.ajax({
        url,
        data:{
          page:this.currentPage,
          pageSize:this.pageSize
        },
        type:'GET'
      })
      .then(res => {
        this.loading = false;
        if(res.code == 200){
          this.tableData = res.data.rows;
          this.totalData = +res.data.total;
        }
      })
      .catch(e => {
        this.loading = false;
      })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
      this.getList();
    }
  },
  mounted(){
    var _this = this;
    this.getList();
  },
  components:{
  }
}
</script>

<style scoped lang='scss'>
  @import '../../assets/scss/tool.scss';
  .home{
    
  }
  .cover{
    width: 100px;
    height: 100px;
  }
</style>